home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_356 / algorhythms / source / musictimer.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  101 lines

  1. /*automusictimer.c*/
  2. /* Copyright 1990 Thomas E. Janzen All Rights Reserved */
  3. /*
  4. **  FACILITY:
  5. **
  6. **    AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
  7. **    compiled with Lattice (TM) C 5.05
  8. **
  9. **  ABSTRACT:
  10. **
  11. **    Algorhythms improvises music over the MIDI serial port.
  12. **
  13. **  AUTHORS: Thomas E. Janzen
  14. **
  15. **  CREATION DATE:    26-MAR-1990
  16. **
  17. **  MODIFICATION HISTORY:
  18. **    DATE    NAME    DESCRIPTION
  19. **--
  20. */
  21. #include "exec/types.h"
  22. #include "exec/nodes.h"
  23. #include "exec/lists.h"
  24. #include "exec/memory.h"
  25. #include "exec/interrupts.h"
  26. #include "exec/ports.h"
  27. #include "exec/libraries.h"
  28. #include "exec/tasks.h"
  29. #include "exec/io.h"
  30. #include "exec/devices.h"
  31. #include "devices/timer.h"
  32. #include <proto/dos.h>
  33. #include <proto/graphics.h>
  34. #include <proto/exec.h>
  35. #include <proto/mathffp.h>
  36. #include <proto/intuition.h>
  37.  
  38. APTR TimerBase;
  39. extern struct GfxBase *GfxBase;
  40. extern struct IntuitionBase *IntuitionBase;
  41. extern struct DOSBase *DOSBase;
  42. extern struct MathBase *MathBase;
  43.  
  44. struct timerequest *tr;
  45. extern struct IORequest *CreateExtIO();
  46.  
  47. extern struct timerequest *CreateTimer(ULONG unit);
  48.  
  49. int DeleteTimer(struct timerequest *);
  50.  
  51. struct timerequest *CreateTimer(ULONG unit) {
  52.     int error;
  53.     struct MsgPort *timerport;
  54.     struct timerequest *timermsg;
  55.     timerport=CreatePort(NULL,0);
  56.     if(timerport==NULL) {
  57.         return(NULL);
  58.     }
  59.     timermsg=(struct timerequest *)
  60.         CreateExtIO(timerport,sizeof(struct timerequest));
  61.     if(timermsg==NULL) {
  62.         return(NULL);
  63.     }
  64.     error=OpenDevice(TIMERNAME,unit,timermsg,0);
  65.     if(error!=0) {
  66.         DeleteTimer(timermsg);
  67.         return(NULL);
  68.     }
  69.     return(timermsg);
  70. }
  71.  
  72. int StartTimer(void) {
  73.     tr=CreateTimer(UNIT_MICROHZ);
  74.     if(tr==0)return(-1);
  75.     return (0);
  76. }
  77.  
  78. int GetSysTime(struct timeval *tv) {
  79.     tr->tr_node.io_Command=TR_GETSYSTIME;
  80.     DoIO(tr);
  81.     *tv=tr->tr_time;
  82.     return (0);
  83. }
  84.  
  85. void RemoveTimer(void) {
  86.     DeleteTimer(tr);
  87. }
  88.  
  89. int DeleteTimer(struct timerequest *tr) {
  90.     struct MsgPort *tp;
  91.     if(tr != 0) {
  92.         tp=tr->tr_node.io_Message.mn_ReplyPort;
  93.         if(tp!=0) {
  94.             DeletePort(tp);
  95.         }
  96.         if (tr) CloseDevice(tr);
  97.         DeleteExtIO(tr,sizeof(struct timerequest));
  98.     }
  99.     return 0;
  100. }
  101.